package com.hippo.core.controller;

import com.alibaba.fastjson.JSONObject;
import com.hippo.core.config.annotation.RequiresPermissions;
import com.hippo.core.service.CaseConfigService;
import com.hippo.core.util.CommonUtil;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.*;

/**
 * @author: hippo
 */
@RestController
public class CaseConfigController {

    @Autowired
    private CaseConfigService caseConfigService;

    @RequiresPermissions("caseConfig:list")
    @PostMapping("/getCaseConfigList")
    public JSONObject getCaseConfigList(@RequestBody JSONObject data) {
        return caseConfigService.getCaseConfigList(data);
    }

    @RequiresPermissions("caseConfig:add")
    @PostMapping("/addCaseConfig")
    public JSONObject addCaseConfig(@RequestBody JSONObject data) {
        CommonUtil.hasAllRequired(data, "name,description,content,createUser");
        return caseConfigService.addCaseConfig(data);
    }

    @RequiresPermissions("caseConfig:delete")
    @DeleteMapping("/deleteCaseConfig/{id}")
    public JSONObject deleteCaseConfig(@PathVariable String id) {
        return caseConfigService.deleteCaseConfig(id);
    }

    @RequiresPermissions("caseConfig:update")
    @PutMapping("updateCaseConfig")
    public JSONObject updateCaseConfig(@RequestBody JSONObject data) {
        return caseConfigService.updateCaseConfig(data);
    }
}
